package com.supreme.scheduleserver.controller;

import com.supreme.commonboot.utils.AjaxResp;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "schedule-task")
public class ScheduleTaskController {

    @Resource
    private ThreadPoolTaskExecutor taskExecutor;

    @GetMapping(value = "test")
    public AjaxResp scheduleTaskTest() {
        return new AjaxResp("scheduleTaskTest");
    }

    @GetMapping(value = "taskExecutor")
    public AjaxResp taskExecutor() {
        return new AjaxResp()
                .append("CorePoolSize", taskExecutor.getCorePoolSize())
                .append("MaxPoolSize", taskExecutor.getMaxPoolSize())
                .append("PoolSize", taskExecutor.getPoolSize())
                .append("ActiveCount", taskExecutor.getActiveCount())
                .append("KeepAliveSeconds", taskExecutor.getKeepAliveSeconds())
                .append("ThreadPriority", taskExecutor.getThreadPriority())
                .append("ThreadNamePrefix", taskExecutor.getThreadNamePrefix());
    }
}
